<%@page import="org.apache.commons.lang.StringUtils"%>
<%@page import="com.google.gson.reflect.TypeToken"%>
<%@page import="com.shareinfo.struts.bulletinInfo.BulletinInfoLogic"%>
<%@page import="com.shareinfo.hibernate.persistent.BulletinInfo"%>
<%@page import="com.shareinfo.common.util.GsonUtil"%>
<%@page import="com.shareinfo.struts.config.ConfigLogic"%>
<%@page import="com.shareinfo.struts.book.StbSession"%>
<%@page import="com.shareinfo.hibernate.persistent.TmianType"%>
<%@page import="java.math.BigDecimal"%>
<%@page import="com.shareinfo.struts.TmianType.TmianTypeLogic"%>
<%@page import="com.shareinfo.hibernate.persistent.Tbookinfo"%>
<%@page import="com.shareinfo.struts.TjspParams.common.CommonParam"%>
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" deferredSyntaxAllowedAsLiteral="true"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
		+ request.getServerName()+ ":" + request.getServerPort()
		+ path + "/";
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
request.setCharacterEncoding("UTF-8");
StbSession stbSession = (StbSession) request.getSession().getAttribute("IPTV_SESSION") ; 


ConfigLogic configLogic = new ConfigLogic();

String page_size = configLogic.getByParam("IPTV_PAGE_SIZE_COMMON_SET","1280*720");
String[] pageWH = page_size.split("\\*");
boolean isHD= false;
if(page_size.contains("1280")){
	isHD = true;
}

String bid = request.getParameter("bid");//上传图片公告
String succBid = request.getParameter("succBid");//成功公告
String failBid = request.getParameter("failBid");//失败公告
String flag = request.getParameter("flag");//如果flag=1,返回使用go(-1)
String time = request.getParameter("time");//时间，秒 （暂时没用，先读取公告的配置）
String level = request.getParameter("level");

BulletinInfo bInfo = null;
CommonParam data = null;

try{
	if(StringUtils.isNotEmpty(bid)){
		 bInfo = new BulletinInfoLogic().findBulletinInfo(String.valueOf(bid));
		 data = GsonUtil.fromJson(bInfo.getParam(), new TypeToken<CommonParam>() {}.getType());
	}

}catch(Exception e){
	//e.printStackTrace();
}
request.setAttribute("data", data);
//http://127.0.0.1:8080/IPTV/iptv/tianjin/dadishu/index.jsp?succBid=***&failBid=***&level=1

//iptv/tianjin/jieshuiguo/index.jsp?succBid=***&failBid=***


String baseHref = basePath + "material/bulletin/" + bid + "/";
baseHref = basePath + "iptv/tianjin/dadishu/images/";

/**







*/
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=baseHref%>"/>
   
    <title>打地鼠</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta name="page-view-size"    content="<%=page_size %>" />
	<script src="<%=basePath%>iptv/tianjin/js/prototype1.6.js"></script>
	
	<style>
			.gz{
				background-repeat: no-repeat;
			}
	</style>
  </head>
  
  <body>
    <div id="bg_div" style="POSITION: absolute; TOP:0px; LEFT:0px; width:<%=page_size.split("\\*")[0]%>px; height:<%=page_size.split("\\*")[1]%>px;z-index: -1">
		<!-- 背景图片 -->
		<img id="img_x" width="100%" height="100%" src="beijing.png" />
	</div>
	
	<div id="divFocus" style="POSITION: absolute; TOP:460px; LEFT:945px; width:209px; height:232px;z-index: 33">
		<!-- 焦点图片-->
		<img id="img_Focus"  src="chui.png" />
	</div>
	
	<div id="divXg" style="POSITION: absolute; TOP:542px; LEFT:945px; width:115px; height:101px;z-index: 33">
		<!-- 焦点图片-->
		<img id="img_Xg" width="100%" height="100%"   src="tm.png" />
	</div>
	
	<div id="divDd1" class="dd" style="POSITION: absolute; TOP:415px; LEFT:398px; width:123px; height:100px;z-index: 10">
		<img id="img_Dd1"  src="nor.png" />
	</div>
	
	<div id="divDd2" class="dd1" style="POSITION: absolute; TOP:415px; LEFT:583px; width:123px; height:100px;z-index: 10">
		<img id="img_Dd2"  src="nor.png" />
	</div>
	
	<div id="divDd3" class="dd" style="POSITION: absolute; TOP:415px; LEFT:757px; width:123px; height:100px;z-index: 10">
		<img id="img_Dd3"  src="nor.png" />
	</div>
	
	<div id="divDd4" class="dd" style="POSITION: absolute; TOP:542px; LEFT:219px; width:123px; height:100px;z-index: 10">
		<img id="img_Dd4"  src="nor.png" />
	</div>
	
	<div id="divDd5" class="dd" style="POSITION: absolute; TOP:542px; LEFT:401px; width:123px; height:100px;z-index: 10">
		<img id="img_Dd5"  src="nor.png" />
	</div>
	
	<div id="divDd6" class="dd" style="POSITION: absolute; TOP:542px; LEFT:583px; width:123px; height:100px;z-index: 10">
		<img id="img_Dd6"  src="nor.png" />
	</div>
	
	<div id="divDd7" class="dd" style="POSITION: absolute; TOP:542px; LEFT:764px; width:123px; height:100px;z-index: 10">
		<img id="img_Dd7"  src="nor.png" />
	</div>
	
	<div id="divDd8" class="dd" style="POSITION: absolute; TOP:542px; LEFT:945px; width:123px; height:100px;z-index: 10">
		<img id="img_Dd8"  src="nor.png" />
	</div>
	
	
	
	<div id="score" style="POSITION: absolute; TOP:80px; LEFT:1035px; width:80px; height:44px;line-height:44px;font-size: 30px; color:red;z-index: 99">0
	</div>
	
	<div id="time" style="POSITION: absolute; TOP:80px; LEFT:1163px; width:80px; height:44px;line-height:44px;font-size: 30px; color:red;z-index: 99">90
	</div>
    
  </body>
  <script  type="text/javascript">
  
  
  //页面全局加载对象、逻辑、布局、计算等处理
  var LoadInit = Class.create({
		initialize: function(key){
			this.styleTemplate = new Template('position: absolute; top: #{top}px; left: #{left}px; height: #{height}px; width: #{width}px;'); //syle 样式模板
			this.focusParam = focusParam; 	//焦点移动配置信息
			this.buttons = {}; 				//元素按钮配置
			this.time = 90; 				//默认定时时间
			this.speed = 800;
			
			this.isSucc = false;				
			this.isOnkeyDown = false;
			this.lkWeizhi = 1;
			this.chuiWeizhi = 1;
			this.weizhis = [1,2,3,4,5,6,7,8];
			this.score = 0;
			this.inter1;
			
			this.initMove();
			
			this.strat();
		},
		
		addPageElement: function(id, eleInfo, cla){	//增加页面元素
			var newElement = new Element('div', {id: id, 'class': cla, style: this.styleTemplate.evaluate(eleInfo) });
			if('ele' == cla){
				newElement.writeAttribute({url: this.buttons[id].action, onin: 'javascript:myPage.oninFun("' + id + '");', onout: 'javascript:myPage.onoutFun("' + id + '");'});
				var newImgElement = new Element('img', { id: 'img_' + id.replace('a_', ''), width: eleInfo.width, height: eleInfo.height, src: this.buttons[id].focusImage});
				newElement.appendChild(newImgElement);
			}else if('move' == cla){
				var newImgElement = new Element('img', { id: 'img_' + id.replace('a_', ''), width: eleInfo.width, height: eleInfo.height, src: eleInfo.img});
				newElement.appendChild(newImgElement);
			}else if('gz' == cla){
				//newElement.setStyle({'background-image': 'url('+ eleInfo.img +')'});
				newElement.setStyle({'background-color': ''});
			}
			document.body.appendChild(newElement);
		},
		
		oninFun: function(id){	//获取焦点
			$('divFocus').setStyle({width: $(id).getStyle('width'), height: $(id).getStyle('height'), top: $(id).getStyle('top'), left: $(id).getStyle('left')});
				var tempImg = this.buttons[id].focusImage;
				if(tempImg.indexOf('_')>0)tempImg = tempImg.split('_')[0] + '.png';
				$('img_Focus').src = '_' + tempImg ; 
		},
		
		onoutFun: function(id){		//失去焦点
			console.log('onoutFun');			
		},
		
		
		EleInfo: function (width, height, top, left, img){	//宽度,高度,y距离,x距离
			var info = {};
			info.width = width;
			info.height = height;
			info.top = top;
			info.left = left;	
			info.img = img;	
			return info;
		},
		
		initMove: function(){
			if(this.focusParam && this.focusParam != ''){
				var kyeEles = this.focusParam.split(':');
				for ( var i = 0; i < kyeEles.length; i++) {
					var temp = kyeEles[i].split('=');
					var temp_ = temp[1].split(',');
					this.buttons['a_' + temp[0] ] = this.KeyMove('a_' + temp[0], '', 'a_' + temp_[0], 'a_' + temp_[1], 'a_' + temp_[2], 'a_' + temp_[3], '');
				}
			}
		},
		
		KeyMove: function (id, action, up, down, left, right, focusImage){ 	//焦点对象
			var info = {};
			info.id =  id;
			info.action =  action;
			info.up =  up;
			info.down =  down;
			info.left =  left;
			info.right =  right;
			info.focusImage =  focusImage;
			return info;
		},
		
		back: function(){
			if('<%=flag%>' == '1'){
				window.history.go(-1);
			}else{
				if('<%=failBid%>' == 'null' || '<%=failBid%>' == ''){
					window.location.href = "<%=basePath%>${data.backUrl}";
				}else{
				 	window.location.href = '<%=basePath%>iptv/BulletAction.do?method=bulletin1&bid=<%=failBid%>';//返回按失败处理
				}
			}
		},
		
		changeActive: function(key, type){	//改变 焦点对象
			
			
			
			if(type == 1){ //上
				currActive = this.buttons[key].up;
			}else if (type == 2){ //下
				currActive = this.buttons[key].down;
			}else if(type == 3){ //左
				currActive = this.buttons[key].left;
			}else if(type == 4){ //右
				currActive = this.buttons[key].right;
			}else{
				currActive = key;
			}
			if(currActive == 'a_0'){
				currActive = key;
				return;
			} 	
		
			var temps =  currActive.split('_');
			$('divFocus').setStyle({top:  (Element.cumulativeOffset($('divDd' + temps[1])).top - 82), left: $('divDd' + temps[1]).getStyle('left')});
			$('divXg').setStyle({top:   $('divDd' + temps[1]).getStyle('top'), left: $('divDd' + temps[1]).getStyle('left')});
			this.chuiWeizhi = temps[1];
			
		},
		
		
		
		changeWeizhi: function(){
			var _selt = this;
			var n = Math.floor(Math.random()* this.weizhis.length);
			if( this.lkWeizhi == n) return this.changeWeizhi();
			this.lkWeizhi = n;
			var ele = $('divDd' + this.weizhis[n] );
			this.lkWeizhi = n;
			if('<%=level%>' == '2'){
				ele.down('img').src = 'm2g.png';
			}else if('<%=level%>' == '3'){
				ele.down('img').src = 'm3g.png';
			}else{
				ele.down('img').src = 'm1g.png';
			}
			
			this.isSucc = true;
			setTimeout(function(){
				_selt.isSucc = false;
			}, 800);
			setTimeout(function(){
				ele.down('img').src = 'nor.png';
			}, 1000);
		},
		
		strat: function(){
			var _selt = this;
			_selt.inter1 = setInterval(function(){
				_selt.changeWeizhi();
			}, 1200);
		},
		
		qrFun: function(){
			var _selt = this;
			if(_selt.isOnkeyDown) return ;
			_selt.isOnkeyDown = true;
			$('img_Focus').src = 'chui2.png';
			setTimeout(function(){
				if(_selt.chuiWeizhi-1 == _selt.lkWeizhi && _selt.isSucc){
					_selt.score = _selt.score +1;
					$('score').innerHTML = _selt.score;
					$('img_Xg').src = 'get.png';
					
				}else{
					$('img_Xg').src = 'miss.png';
				}
				setTimeout(function(){
					$('img_Xg').src = 'tm.png';
					_selt.isOnkeyDown = false;
				}, 200);
			}, 100);
			setTimeout(function(){
				$('img_Focus').src = 'chui.png';
			}, 200);
		},
		
		comparison: function(){	//比较是否成功
			
		},
		
		successUrl: function(){
			var url ='<%=basePath%>iptv/tianjin/dadishu/index.jsp?succBid=<%=succBid%>&failBid=<%=failBid%>';
			if('<%=level%>' == '2') {
				url = url + '&level=' + 3;
			}else if('<%=level%>' == '3'){
				url = '<%=basePath%>iptv/BulletAction.do?method=bulletin1&bid=<%=succBid%>';
				//return ;
			}else{
				url = url + '&level=' + 2;
			}
			window.location.href = url;
		},
			
		
		failUrl: function(){
			window.location.href = '<%=basePath%>iptv/BulletAction.do?method=bulletin1&bid=<%=failBid%>';
		},
		
		MyKeyEvent: function(keyEvent){ //监听键值
			if(this.isOnkeyDown) return ;
			keyEvent = keyEvent ? keyEvent : window.event;
			keyEvent.which = keyEvent.which ? keyEvent.which : keyEvent.keyCode;
			switch(keyEvent.which ){
				case 37://'left';							
					this.changeActive(currActive, 3);
					break;
				case 38://'up';
					this.changeActive(currActive, 1);
					break;
				case 39://'right';
					this.changeActive(currActive, 4);
					break;
				case 40://'down';
					this.changeActive(currActive, 2);
					break;
				case 13:
				case 66:
					this.qrFun();
					break;
				case 81:
				case 8:
				case 1249:
				case 640:
					this.back();
					break;
			}
		}
  });
  var currActive; 				//当前元素		
  var defaultActive = ''; 		//默认焦点
  var focusParam = '8#JD:1=0,5,0,2:2=0,6,1,3:3=0,7,2,0:4=1,0,0,5:5=1,0,4,6:6=2,0,5,7:7=3,0,6,8:8=3,0,7,0';
  //focusParam = '${data.dFocus}';
  var myPage;  //全局对象
  
  Event.observe(window, 'load', function() {  //绑定页面加载
	  
	  if(focusParam.indexOf('#') > 0){//默认焦点id
		  defaultActive = 'a_' + focusParam.slice(0,focusParam.indexOf('#'));
	  }else{
		  defaultActive = 'a_' + focusParam.slice(0,focusParam.indexOf('JD:'));
	  }
  
	  focusParam = focusParam.slice(focusParam.indexOf('JD:')+3);
		
	  myPage = new LoadInit(defaultActive);//初始化页面
		
	  window.document.onkeydown = myPage.MyKeyEvent.bind(myPage);	 //绑定按键
		
	  myPage.changeActive(defaultActive);
		
	  var timeInter = setInterval(function(){
			if($('time')){
				var t = parseInt(document.getElementById('time').innerHTML);
				if(t == 0){
					clearInterval(timeInter);
					if(myPage.inter1) clearInterval(myPage.inter1);;
					if(myPage.score >= 6){
						console.log('succ');
						myPage.successUrl();
					}else{
						console.log('fail');
						myPage.failUrl();
					}
					myPage.isOnkeyDown = true;
				}else{
					document.getElementById('time').innerHTML = (--t);
				};
			};
		}, 1000);
	  console.log(myPage);
	  
	  
	  
	});
  
  
  

  </script>
</html>























